package com.jtny.nytb.equipment.pool;

import org.springframework.stereotype.Component;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author 智慧能源中心 - 伍天宇
 * @package com.jtny.nytb.energymonitor.pool
 * @fileName TenantDataCalThreadPool.java
 * @createTime 2023年11月27日 21:41
 * @Copyright© 2023 jtny
 * 江投能源技术研究院 版权所有
 */
@Component
public class TenantDataCalThreadPool extends ThreadPoolExecutor {

    private static final int QUEUE_CAPACITY = 500;

    public TenantDataCalThreadPool() {
        super(10, 20, 60, TimeUnit.SECONDS, new LinkedBlockingQueue(QUEUE_CAPACITY), Executors.defaultThreadFactory(),
                new CallerRunsPolicy());
    }

    /**
     * 是否有空间存储当前的数量
     *
     * @param curPutInCount
     * @return
     */
    public synchronized boolean isCanPutIn(int curPutInCount) {
        int size = getQueue().remainingCapacity();
        return size - curPutInCount > 0;
    }

}